package com.load.factories;

import static com.database.objects.Priority.*;
import static com.metrics.objects.Options.*;

import java.util.Map;

import com.database.objects.*;
import com.load.utils.KeyIssue;

public class IssueFactory {

	public static Issue createIssue(Project project, Map<KeyIssue, String> issueMap) {
		Long number = Long.valueOf(issueMap.get(KeyIssue.NUMBER));
		String date = issueMap.containsKey(KeyIssue.DATE) ? issueMap.get(KeyIssue.DATE) : START_DATE_DEFAULT;

		Type type = Type.createType(issueMap.get(KeyIssue.TYPE));
		Status status = Status.createStatus(issueMap.get(KeyIssue.STATUS));

		Distribution distribution = project.getTrackerRepository().getDistribution();
		Integer priority = scaleAccordingDistribution(distribution, issueMap.get(KeyIssue.PRIORITY));
		String description = issueMap.get(KeyIssue.DESCRIPTION);
		Developer developer = project.getDeveloperByName(issueMap.get(KeyIssue.DEVELOPER));

		if (developer != null) {
			return new Issue(number, date, type, status, priority, description, developer);
		}
		return null;
	}

}
